using System.Data;
using PCSComUtils.Common;

using PCSComPayroll.DS;

namespace PCSComPayroll.BO
{
	public class PaymentRequestApprovalBO
	{
		//[AutoComplete(true)]
		public DataSet List(int pintMasterID)
		{
			PAY_PaymentRequestDetailDS dsDetail = new PAY_PaymentRequestDetailDS();
			return dsDetail.List(pintMasterID);
		}
		#region IObjectBO Members

		//[AutoComplete(true)]
		public void UpdateDataSet(DataSet dstData)
		{
			PAY_PaymentRequestDetailDS dsDetail = new PAY_PaymentRequestDetailDS();
			dsDetail.UpdateDataSet(dstData);
		}

		public void Update(object pObjectDetail)
		{
			// TODO:  Add PaymentRequestApprovalBO.Update implementation
		}

		public void Delete(object pObjectVO)
		{
			// TODO:  Add PaymentRequestApprovalBO.Delete implementation
		}

		//[AutoComplete(true)]
		public void Delete(int pintMasterID, int pintEstimasterMasterID, int pintProductionLineID, int pintSaleOrderDetailID)
		{
			PAY_PaymentRequestDetailDS dsDetail = new PAY_PaymentRequestDetailDS();
			PAY_PaymentRequestMasterDS dsMaster = new PAY_PaymentRequestMasterDS();
			dsDetail.DeleteByMaster(pintMasterID);
			dsMaster.Delete(pintMasterID);
			PAY_EstimateDetailDS dsEstimate = new PAY_EstimateDetailDS();
			dsEstimate.UpdateAmount(pintEstimasterMasterID, pintProductionLineID, pintSaleOrderDetailID);
		}

		public void Add(object pObjectDetail)
		{
			// TODO:  Add PaymentRequestApprovalBO.Add implementation
		}

		//[AutoComplete(true)]
		public object GetObjectVO(int pintID, string VOclass)
		{
			PAY_PaymentRequestMasterDS dsMaster = new PAY_PaymentRequestMasterDS();
			return dsMaster.GetObjectVO(pintID);
		}

		#endregion

		//[AutoComplete(true)]
		public int AddAndReturnID(object pvoMaster, int pintEstimasteMasterID, DataSet pdstData)
		{
			PAY_PaymentRequestMasterDS dsMaster = new PAY_PaymentRequestMasterDS();
			PAY_PaymentRequestMasterVO voMaster = (PAY_PaymentRequestMasterVO)pvoMaster;
			int intNewID = dsMaster.AddAndReturnID(voMaster);
			voMaster.PaymentRequestMasterID = intNewID;
			foreach (DataRow drowData in pdstData.Tables[0].Rows)
				if (drowData.RowState != DataRowState.Deleted)
					drowData[PAY_PaymentRequestDetailTable.PAYMENTREQUESTMASTERID_FLD] = intNewID;
			PAY_PaymentRequestDetailDS dsDetail = new PAY_PaymentRequestDetailDS();
			dsDetail.UpdateDataSet(pdstData);
			
			PAY_EstimateDetailDS dsEstimate = new PAY_EstimateDetailDS();
			dsEstimate.UpdateAmount(pintEstimasteMasterID, voMaster.ProductionLineID, voMaster.SaleOrderDetailID);
			return intNewID;
		}

		//[AutoComplete(true)]
		public void Update(object pObjectDetail, int pintEstimasteMasterID, DataSet pdstData)
		{
			PAY_PaymentRequestMasterDS dsMaster = new PAY_PaymentRequestMasterDS();
			PAY_PaymentRequestMasterVO voMaster = (PAY_PaymentRequestMasterVO)pObjectDetail;
			dsMaster.Update(voMaster);
			PAY_PaymentRequestDetailDS dsDetail = new PAY_PaymentRequestDetailDS();
			dsDetail.UpdateDataSet(pdstData);

			PAY_EstimateDetailDS dsEstimate = new PAY_EstimateDetailDS();
			dsEstimate.UpdateAmount(pintEstimasteMasterID, voMaster.ProductionLineID, voMaster.SaleOrderDetailID);
		}
		//[AutoComplete(true)]
		public decimal GetAvailableAmount(int pintSaleOrderDetailID, int pintProductionLineID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.GetAvailableAmount(pintSaleOrderDetailID, pintProductionLineID);
		}
		//[AutoComplete(true)]
		public decimal GetCompleteAmount(int pintSaleOrderDetailID, int pintProductionLineID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.GetCompleteAmount(pintSaleOrderDetailID, pintProductionLineID);
		}
		//[AutoComplete(true)]
		public decimal GetTotalRequest(int pintSaleOrderDetailID, int pintProductionLineID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.GetTotalRequest(pintSaleOrderDetailID, pintProductionLineID);
		}
		//[AutoComplete(true)]
		public decimal GetTotalPaymentRequest(int pintSaleOrderDetailID, int pintProductionLineID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.GetTotalPaymentRequest(pintSaleOrderDetailID, pintProductionLineID);
		}
		//[AutoComplete(true)]
		public bool IsWOCompleted(int pintSaleOrderDetailID, int pintProductionLineID)
		{
			PAY_EstimateDetailDS dsDetail = new PAY_EstimateDetailDS();
			return dsDetail.IsWOCompleted(pintSaleOrderDetailID, pintProductionLineID);
		}
		//[AutoComplete(true)]
		public DataTable GetEstimateData(int pintSaleOrderDetailID)
		{
			PAY_EstimateDetailDS dsEstimateDetail = new PAY_EstimateDetailDS();
			return dsEstimateDetail.GetEstimateDetailBySale(pintSaleOrderDetailID);
		}
	}
}
